// 取
function getStorageSync(key){
	if(!key) return null
	try{
		const val = uni.getStorageSync(key)
		return JSON.parse(val)
	}catch(e){
		//TODO handle the exception
		return null
	}
	
}

// 异步增改
function setStorage(key, val){
	if(!key) return
	uni.setStorage({
		key,
		data: JSON.stringify(val)
	})
}

// 同步增改
function setStorageSync(key, val){
	if(!key) return false
	try{
		uni.setStorageSync(key, JSON.stringify(val))
		return true
	}catch(e){
		//TODO handle the exception
		return false
	}
}

// 删
function removeStorageSync(key){
	if(!key) return false
	try{
		uni.removeStorageSync(key)
		return true
	}catch(e){
		//TODO handle the exception
		return false
	}
}

module.exports = {
	getStorageSync,
	setStorage,
	setStorageSync,
	removeStorageSync
}